package com.dz.lm.web.controller.login;

import com.alibaba.fastjson.JSONObject;
import com.dz.lm.common.exception.ServiceException;
import com.dz.lm.web.controller.BasicControl;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

import java.io.IOException;
import java.util.Map;

/**
 * error处理
 * 
 * @author zhanghairong
 */
@Controller
@RequestMapping("/rewriteUrl/error")
public class ErrorDoFilterControl extends BasicControl{
	
	public Logger logger = LogManager.getLogger(ErrorDoFilterControl.class);
    
    /**
     * 校验DoFilter
     * 
     * @return
     * @throws IOException
     */
    @ResponseBody
    @RequestMapping("/validDoFilter")
    public Map<String, Object> validDoFilter(HttpServletRequest request) throws ServiceException {
    	JSONObject subjo = new JSONObject();
    	request.setAttribute("reqKey", request.getParameter("reqKey"));
    	if ("1".equals(request.getParameter("type"))) {
        	subjo.put("result", "09");
        	subjo.put("message", "参数为空或参数异常!");
    	} else if ("2".equals(request.getParameter("type"))) {
        	subjo.put("result", "10");
        	subjo.put("message", "登录已失效请重新登录!");
    	} else if ("3".equals(request.getParameter("type"))) {
        	subjo.put("result", "11");
        	subjo.put("message", "系统异常，请稍后重试!");
    	}
    	return parameterEncrypt(request, subjo);
    }
}
